function stupid () {

	var modaldiv = document.createElement('div');
  	modaldiv.setAttribute('id','modaldiv');
  	modaldiv.innerHTML = 'Element Number has been added! ';

	var h1 = document.createElement('h1')
  	h1.innerHTML = 'Add Movie';
  	modaldiv.appendChild(h1);


	var form = document.createElement('form')
  	form.setAttribute('onsubmit','AddMovie(this); return false;');
  	modaldiv.appendChild(form);


	var div = document.createElement('div')
  	div.innerHTML = 'Movie Name:';
	var input = document.createElement('input')
  	input.setAttribute('type','text');
  	input.setAttribute('name','name');
	div.appendChild(input)
  	modaldiv.appendChild(div);

	var div = document.createElement('div')
  	div.innerHTML = 'Rating:';
	var select = document.createElement('select')
  	select.setAttribute('name','rating');
	div.appendChild(input)
  	modaldiv.appendChild(div);
	$.modal(modaldiv);
}

function AddMovieForm () {
	$.modal('<div><h1>Add Movie</h1><form onsubmit="AddMovie(this); return false;"><div>Movie name:<input type="text" name="name"/></div>Rating: <span class="stars" id="stars-cap-newmovie"></span><span id="stars-wrapper-newmovie"><select name="rating"><option value="1">Terrible</option><option value="2">Not that bad</option><option value="3">Average</option><option value="4">Good</option><option value="5" selected="selected">Awesome</option></select></span><div><input type="submit" value="Add Movie"></div></form></div>');

	$("#stars-wrapper-newmovie").stars({
		captionEl: $("#stars-cap-newmovie"),
     	inputType: "select"
	}); 
}

function AddMovie (form) {
    $.getJSON("rpc", { action: "AddMovie", name: form.name.value, rating:form.rating.value },  function(data){
        if (data.error) {
            alert("Warning: " + data.error + "!")
        } else {
    		GetMovies();
            alert("Added " + data.name + " to the list!");
			$.modal.close();
        }
    });
}

function RateMovie (form) {
    var movie = form.movie.value;
    var rating = form.rating.value;
    if (confirm("You have seen and want want to rate "+ form.name.value +" a "+ rating +"?")) {
        $.getJSON("rpc", { action: "RateMovie", movie: movie, rating:rating },  function(data){
            if (data.error) {
                alert("Warning: " + data.error + "!")
            } else {
                alert("Rated " + data.name + " and added it to the list of movies you have seen!");
            }
        });
    } else {
        $("#stars-wrapper-" + movie).stars("select", form.oldrating.value);
    }
}


function AddToMyList (movie) {
    $.getJSON("rpc", { action: "AddToMyList", movie: movie },  function(data){
        if (data.error) {
            alert("Warning: " + data.error + "!")
        } else {
            alert("Added " + data.name + " to my must see list!");
        }
    });
}

function GetMovies(){
    $("#movielist").html('');
    $.getJSON("/rpc", { action: "GetMovies" },  function(data){
        var count = 0;
        for (var i in data.movies) {
            movie = data.movies[i];
            var html = '<div class="movie" id="'+movie.key+'">';
            html += (parseInt(i) + 1) + ") " + movie.name + " ";
            html += '[ <form id="rateform-'+ movie.key + '" onclick="RateMovie(this)" style="display:inline-block;">';
            html += '<input type="hidden" name="movie" value="'+movie.key+'"/>\
            <input type="hidden" name="name" value="'+movie.name+'"/>\
            <input type="hidden" name="oldrating" value="'+movie.rating+'"/>\
				 <span id="stars-wrapper-'+movie.key+'">\
         <select name="rating" >\
             <option value="1">Terrible</option>\
             <option value="2">Not that bad</option>\
             <option value="3">Average</option>\
             <option value="4">Good</option>\
             <option value="5">Awesome</option>\
         </select>\
     </span>\
              </form> ]\
  (' + movie.votes+ ' votes)\
<input type="button" onclick="AddToMyList(\''+movie.key+'\')" value="Add to my list"/>\
 added by <a href="/profile/'+movie.user+'">'+movie.user+'</a>';

html += "</div>";
            $("#movielist").append(html);
            $("#stars-wrapper-" + movie.key).stars({
                captionEl: $("#stars-cap-" + movie.key),
                cancelShow: false,
                inputType: "select"
            });
            $("#stars-wrapper-" + movie.key).stars("select", movie.rating);
        }
        movie = null;
    });
}

function GetMoviesIveSeen(nickname){
    $("#seen").html('');
    $.getJSON("/rpc", { action: "GetMoviesIveSeen", nickname:nickname },  function(data){
        var count = 0;
        for (var i in data.movies) {
            movie = data.movies[i];
            var html = '<div class="movie" id="'+movie.key+'">';
            html += (parseInt(i) + 1) + ") " + movie.name + " ";
            html += '[ <form id="rateform-'+ movie.key + '" onclick="RateMovie(this)" style="display:inline-block;">';
            html += '<input type="hidden" name="movie" value="'+movie.key+'"/>\
            <input type="hidden" name="name" value="'+movie.name+'"/>\
            <input type="hidden" name="oldrating" value="'+movie.rating+'"/>\
				 <span id="stars-wrapper-'+movie.key+'">\
                    <select name="rating" ><option value="1">Terrible</option><option value="2">Not that bad</option><option value="3">Average</option><option value="4">Good</option><option value="5">Awesome</option></select>\
                </span>\
            </form> ]\
  (' + movie.votes+ ' votes)';

html += "</div>";
            $("#seen").append(html);
            $("#seen #stars-wrapper-" + movie.key).stars({
                captionEl: $("#stars-cap-" + movie.key),
                cancelShow: false,
                inputType: "select"
            });
            $("#seen #stars-wrapper-" + movie.key).stars("select", movie.rating);
        }
        movie = null;
    });
}

function GetMoviesIMustSee(nickname){
    $("#mustsee").html('');
    $.getJSON("/rpc", { action: "GetMoviesIMustSee", nickname:nickname },  function(data){
        var count = 0;
        for (var i in data.movies) {
            movie = data.movies[i];
            var html = '<div class="movie" id="'+movie.key+'">';
            html += (parseInt(i) + 1) + ") " + movie.name + " ";
            html += '[ <form id="rateform-'+ movie.key + '" onclick="RateMovie(this)" style="display:inline-block;">';
            html += '<input type="hidden" name="movie" value="'+movie.key+'"/>\
            <input type="hidden" name="name" value="'+movie.name+'"/>\
            <input type="hidden" name="oldrating" value="'+movie.rating+'"/>\
				 <span id="stars-wrapper-'+movie.key+'">\
         <select name="rating" >\
             <option value="1">Terrible</option>\
             <option value="2">Not that bad</option>\
             <option value="3">Average</option>\
             <option value="4">Good</option>\
             <option value="5">Awesome</option>\
         </select>\
     </span>\
              </form> ]\
  (' + movie.votes+ ' votes)';

html += "</div>";
            $("#mustsee").append(html);
            $("#mustsee #stars-wrapper-" + movie.key).stars({
                captionEl: $("#stars-cap-" + movie.key),
                cancelShow: false,
                inputType: "select"
            });
            $("#mustsee #stars-wrapper-" + movie.key).stars("select", movie.rating);
        }
        movie = null;
    });
}

function GetMoviesIAdded(nickname){
    $("#added").html('');
    $.getJSON("/rpc", { action: "GetMoviesIAdded", nickname:nickname },  function(data){
        var count = 0;
        for (var i in data.movies) {
            movie = data.movies[i];
            var html = '<div class="movie" id="'+movie.key+'">';
            html += (parseInt(i) + 1) + ") " + movie.name + " ";
            html += '[ <form id="rateform-'+ movie.key + '" onclick="RateMovie(this)" style="display:inline-block;">';
            html += '<input type="hidden" name="movie" value="'+movie.key+'"/>\
            <input type="hidden" name="name" value="'+movie.name+'"/>\
            <input type="hidden" name="oldrating" value="'+movie.rating+'"/>\
				 <span id="stars-wrapper-'+movie.key+'">\
         <select name="rating" >\
             <option value="1">Terrible</option>\
             <option value="2">Not that bad</option>\
             <option value="3">Average</option>\
             <option value="4">Good</option>\
             <option value="5">Awesome</option>\
         </select>\
     </span>\
              </form> ]\
  (' + movie.votes+ ' votes)';

html += "</div>";
            $("#added").append(html);
            $("#added #stars-wrapper-" + movie.key).stars({
                captionEl: $("#stars-cap-" + movie.key),
                cancelShow: false,
                inputType: "select"
            });
            $("#added #stars-wrapper-" + movie.key).stars("select", movie.rating);
        }
        movie = null;
    });
}
